*************************************************************************************************************************************************
*																																				*
*																																				*
* Replication do-file for: Creaming among Caseworkers: Effects of Client Competence and Client Motivation on Caseworkers’ Willingness to Help.	*
*																																				*
*																																				*
*	Notes: This do-file replicates the results in "Creaming among Caseworkers: Effects of Client Competence and Client 							*
*	Motivation on Caseworkers’ Willingness to Help." All covariates are excluded for reasons of discretion. Thus this dataset 					*
*	does not allow for replication of Table 3 and model 3 and 5 in Table 4 and Table A1															*			
*																																				*
*																																				*
*																																				*
*************************************************************************************************************************************************

*Set directory:
cd "\your_directory"

*open replication data
use replication_data.dta, clear

*****************************
*							*
*		   Table 4			*
*							*
*****************************
		
*Run all analysis and store results

qui{
eststo clear
global mainvar i.incompetent##i.unmotivated // Specify main independent variables

*Simple OLS model with clustered standard errors. 
*Store main, interaction, and simple effects.
reg willingness $mainvar, cluster(random_groupid)
mat bint=r(table)[1..9,8]
pwcompare $mainvar, effects
mat bmain=r(table_vs)[1..9,1..2]
mat bsimple=r(table_vs)[1..9,3..8]
mat b=bmain,bint,bsimple
mat g=b[1,1..9]
mat se=b[2,1..9]
ereturn post g, obs(1595) dof(49)
estadd mat se
estadd local female="No"
estadd local covar="No"
estadd local fe="No"
eststo m1

*Simple OLS model including client female indicator variable and clustered standard errors. 
*Store main, interaction, and simple effects.
reg willingness $mainvar client_female, cluster(random_groupid)
mat bint=r(table)[1..9,8]
pwcompare $mainvar, effects
mat bmain=r(table_vs)[1..9,1..2]
mat bsimple=r(table_vs)[1..9,3..8]
mat b=bmain,bint,bsimple
mat g=b[1,1..9]
mat se=b[2,1..9]
ereturn post g, obs(1595) dof(49)
estadd mat se
estadd local female="Yes"
estadd local covar="No"
estadd local fe="No"
eststo m2

*Fixed effects model including client female indicator variable and clustered standard errors.
*Store main, interaction, and simple effects.
xtreg willingness $mainvar client_female, fe i(random_groupid) cluster(random_groupid)
mat bint=r(table)[1..9,8]
pwcompare $mainvar, effects
mat bmain=r(table_vs)[1..9,1..2]
mat bsimple=r(table_vs)[1..9,3..8]
mat b=bmain,bint,bsimple
mat g=b[1,1..9]
mat se=b[2,1..9]
ereturn post g, obs(1595) dof(49)
estadd mat se
estadd local female="Yes"
estadd local covar="No"
estadd local fe="Yes"
eststo m4
}

*Table of results
#delimit ;
esttab m1 m2 m4  , b(2) se(2) varwidth(39) nogap compress noobs nonum 
mtitles("(1)" "(2)" "(4)")
title("Table 4. Main Effects, Interaction Effect, and Simple Effects of Treatments on Willingness to Help (0-10). Coefficients and Standard Errors (in Parentheses).")
varlabel(
	1vs0.incompetent "Competence (Novice)"
	1vs0.unmotivated "Motivation (Lazy)"
	1.incompetent#1.unmotivated  "Competence (Novice) × Motivation (Lazy)"
	0vs0.incompetent#1vs0.unmotivated "Lazy Expert vs. Diligent Expert"
	1vs0.incompetent#0vs0.unmotivated "Diligent Novice vs. Diligent Expert"
	1vs0.incompetent#1vs0.unmotivated "Lazy Novice vs. Diligent Expert	"
	1vs0.incompetent#0vs1.unmotivated "Lazy Expert vs. Diligent Novice"
	1vs0.incompetent#1vs1.unmotivated "Lazy Novice vs. Lazy Expert"
	1vs1.incompetent#1vs0.unmotivated "Lazy Novice vs. Diligent Novice"
)
scalar("female Client Female" "covar Covariates" "fe Fixed effects") 
nonotes addnote(Notes: n = 1,595. Absolut differences. Main effects, interaction effect, and simple effects are based on marginal linear predictions of all models (1-5) in Table A1 in the Appendix. Client Female indicates whether Client Female indicator is included. Covariates are not included for reasons of discretion. Thus model 3 and 5 omitted. Number of groups in fixed effects estimation: 50. * p < .05, ** p < .01, *** p < .001.)
refcat(1vs0.incompetent "Main effects" 1.incompetent#1.unmotivated "Interaction effect" 0vs0.incompetent#1vs0.unmotivated  "Simple effects", nolabel)
;

#delimit cr

*****************************
*							*
*		   Figure 2			*
*							*
*****************************

*Save results for figure 2 in proper format. (Based on model 1 in Table A1) 

qui{
eststo clear
recode incompetent (0=1) (1=0), gen(competent) // reverse variable to easily change viewing order in figure 2
recode unmotivated (0=1) (1=0), gen(motivated) // reverse variable to easily change viewing order in figure 2
reg willingness competent##motivated, cluster(random_groupid)
estpost margins motivated, at(competent==0)
eststo c1
reg willingness competent##motivated, cluster(random_groupid)
estpost margins motivated, at(competent==1)
eststo c2
drop competent motivated
}


*Figure with results
#delimit ;
coefplot (c1, label(Novice)) (c2, label(Expert)) , recast(bar) barwidth(.3) fcolor(%80) vertical 
 scheme(s1mono)   grid(none)   coeflabels(0.motivated="Lazy" 1.motivated="Dilligent") 
 addplot( 
 (scatteri 7.5 0.83 7.6 0.83 7.6 1.17 7.5 1.17, recast(connected)  lpattern(solid) msymbol(none)) 
 (scatteri 7.85 .87 "H1", msymbol(none)) 
 (scatteri 7.85 .993 "{&Delta}=.17", msymbol(none)) 
 (scatteri 8.35 .87 "H2 ***{&Delta}=.54", msymbol(none)) 
 (scatteri 8.3 1.17 8.4 1.17 8.4 1.83 8.3 1.83, recast(connected)  lpattern(solid) msymbol(none)) 
 (scatteri 8.6 1.3 "H3 ***{&Delta}=.37", msymbol(none)) 
 (scatteri 8.7 0.83 8.8 0.83  8.8 2.17 8.7 2.17, recast(connected)  lpattern(solid) msymbol(none)) 
 (scatteri 8.9 1.17 9 1.17 9 2.17 8.9 2.17, recast(connected)  lpattern(solid) msymbol(none)) 
 (scatteri 9.1 1.83 9.2 1.83 9.2 2.17 9.1 2.17, recast(connected)  lpattern(solid) msymbol(none)) 
 (scatteri 9 .87 "H4 ***{&Delta}=.93", msymbol(none)) 
 (scatteri 9.2 1.3 "H4 ***{&Delta}=.76", msymbol(none)) 
 (scatteri 9.4 1.85 "H4 **{&Delta}=.39", msymbol(none)) 
 (scatteri 8 0.83 8.1 0.83 8.1 1.83 8 1.83, recast(connected)  lpattern(solid) msymbol(none))) ylabel(0(1)10) ciopts(recast(rcap) lcolor(black)) citop 
 ;
 
 #delimit cr

*****************************
*							*
*		  Table A1			*
*							*
*****************************


*Generate interaction term manually for easier labelling in table.
qui{
gen incompetentXunmotivated = incompetent*unmotivated
lab var incompetentXunmotivate "Competence (Novice) X Motivation (Lazy)"

*Run all analysis and store results
eststo clear
global mainvar incompetent unmotivated incompetentXunmotivated // reset main independent variables

*Simple OLS model with clustered standard errors
eststo: reg willingness $mainvar, cluster(random_groupid)
estadd local covar="No"
estadd local fe="No"

*Simple OLS model including client female indicator variable and clustered standard errors. 
eststo: reg willingness $mainvar client_female, cluster(random_groupid)
estadd local covar="No"
estadd local fe="No"

*Fixed effects model including client female indicator variable and clustered standard errors.
eststo: xtreg willingness $mainvar client_female, fe i(random_groupid) cluster(random_groupid)
estadd local covar="No"
estadd local fe="Yes"
}

*Table of results
#delimit ;
esttab,  label  se(2) b(2) scalar("covar Covariates" "fe Fixed effects" "r2_a Adjusted r-squared")  sfmt(2) nogap compress varwidth (30) nonum 
mtitles("(1)" "(2)" "(4)")
title("Table A1. Effects of Competence and Motivation on Mean Willingness to Help (0-10). OLS Regression. Coefficients and Standard Errors (in Parentheses).") 
nonote addnote(Notes: Standard errors clustered at job center level (in parentheses). Labels in parenthesis indicate level of
variable equal to 1. All reported variables are indicator variables. Client Female indicates whether the described
client was either male or female. The effect of Client Female is insignificant across specifications.
Covariates are not included for reasons of discretion. Thus model 3 and 5 omitted.
Number of groups in fixed effects estimation: 50. * p<.05, ** p<.01, *** p<.001.)
;

#delimit cr

qui: drop incompetentXunmotivated


*****************************
*							*
*		  Table A2			*
*							*
*****************************

*Run all analysis and store results

qui{
eststo clear
eststo: reg check_competence incompetent unmotivated, cluster(random_groupid)
eststo: reg check_motivation incompetent unmotivated, cluster(random_groupid)
}

*Table of results
#delimit ;
esttab , label se(2) b(2) scalar("r2_a Adjusted r-squared") sfmt(2) nogap compress nonum varwidth(20) modelwidth(20)
mtitle("Competence Item" "Motivation Item")
title("Table A2. Manipulation Check. OLS Regression.")
nonotes addnote	(Notes: Standard errors clustered at job center level (in parentheses). Measures based on two survey items: (1) “X seems to have the necessary competences to solve the tasks in the trainee placement” (Competence) (2) “X seems to be motivated to solve the tasks in the trainee placement” (Motivation). 1 = Strongly disagree, 5 = Strongly agree. The questions were asked at the end of the survey. * p < .05, ** p < .01, *** p < .001.)
;

#delimit cr
